-- horizontal_damage
-- create by wangy
-- 技能: 行伤害。以目标为中心，对其同一行范围敌人造成固定伤害

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 3. 伤害/计算伤害固定
        local damage = para[1];

        -- 道具伤害加成
        local prop = PropM.combine(source, "property_damage", 1);
        damage = PropM.apply(prop, damage);

        -- 4. 遍历怪物所在列
        local ret = {};
        local pos = target.dbase:query("pos");
        if not pos then
            pos = target:getOwner();
        end

        local coor = DungeonM.convertToCoor(pos);
        local x;
        local m;

        local cover = { };

        for x = 1, DUNGEON_WIDTH do
            m = DungeonM.convertToPos(x, coor.y);
            table.insert(cover, m);
        end

        local skillInfo = SkillM.query(skillId);

        for _, m in pairs(cover) do
            local grid = DungeonM.getGridByPos(m);

            -- 如果是未翻开的格子
            if  not grid:isOpened() then
                local isQuite = skillInfo.dbase.quite or false;
                local isDelay = skillInfo.dbase.delay or false;
                grid:open(isQuite, isDelay);
            end

            -- 如果是未死亡的怪物
            if  grid:isMonster() and
                not grid.monster:isDead() then

                -- 增加命中动作
                if SkillM.getSequence(grid.monster) == nil then
                    SkillM.getSequenceList()[grid.monster] = CastSequence.create(source, grid.monster, skillId);
                end

                SkillM.getSequence(grid.monster):hit(source, grid.monster, skillId);

                -- 道具修正伤害
                local classId = extra["propertyId"];
                local fixDamage = damage;
                if type(classId) == "number" then
                    fixDamage = PropertyM.fixPropertyDamage(source, grid.monster, classId, fixDamage);
                end

                -- 受创
                CombatM.receiveDamage(source, grid.monster, fixDamage, skillId, extra);

                -- 目标
                table.insert(ret, grid.monster);
            end
        end

        -- 返回作用目标
        return ret;
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        if #arr == 1 then
            return { tonumber(arr[1]), };
        else
            return { tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]), };
        end
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)

        -- 3. 伤害
        local damage = para[1];

        desc = string.gsub(desc, "{damage_mon}", damage);

        -- 系别TODO

        return desc;
    end,
}
